/* << fastinsert report library >> PdfGrid.h Oct 31, 2010
 *
 * 	http://code.google.com/p/libfir
 *
 * Copyright (c) 2005 Pavlo Drobov (drobov.pavel@gmail.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#ifndef PDFGRID_H_
#define PDFGRID_H_

#include "hpdf.h"

#include "GridBase.h"

#define MAYBEFONTSIZE_MAX	14.0f
#define MAYBEFONTSIZE_MIN	6.0f


namespace dasco
{
namespace report
{

//! \struct GridPx
//! \brief physic coordinate in PDF page
struct GridPx
{
	GridPx() :
		columnsWidth(NULL)
	{
	}
	virtual ~GridPx();

	short unsigned columnCnt;
	float fontSize, stepV, *columnsWidth;
};

//! \class CellPdf
//! \brief pdf specific wrapper for Cell
class DLL_EXPORT CellPdf
{
public:
	CellPdf(const ICell*);
	virtual ~CellPdf();

	void render(PdfPage* page,float& indentH,float& indentV) const;

protected:
	const ICell* parent;
};

//! \class RowSetPdf
//! \brief pdf specific wrapper for RowSet
class DLL_EXPORT RowSetPdf
{
protected:
	IRowSet* parent;
public:
	RowSetPdf(IRowSet*);
	virtual ~RowSetPdf();

	unsigned calculateSymbol();

	bool calculateGridForFontSize(const PdfBase*
								 ,__u16*
								 ,const float = MAYBEFONTSIZE_MAX
								 ,const float* = NULL
								 ) const;

	virtual float render(PdfPage*, float&, float&, const GridPx&) const;


	static RowSetPdf * rowSetPdfFactory(IRowSet*);

};


//! \class RowSetHeaderPdf
//! \brief pdf specific wrapper for RowSetHeader
class DLL_EXPORT RowSetHeaderPdf
	: public RowSetPdf
{
public:
	RowSetHeaderPdf(IRowSet*);
	virtual ~RowSetHeaderPdf();

	virtual float render(PdfPage*, float&, float&, const GridPx&) const;
};

//! \class GridPdf
//! \brief pdf specific wrapper for Grid
class DLL_EXPORT GridPdf
{
protected:
	IGrid * parent;
public:
	GridPdf(IGrid*);
	virtual ~GridPdf();


	virtual void render(PdfBase*);

protected:
	HPDF_Outline outline;
	PdfPage* fistPageThisReport;

	void calculateGridPx(PdfBase*,GridPx*) const;
	PdfPage* getNewPage(PdfBase*);

private:
	mutable bool fontFinding;

};


}} //end namespace dasco::report


#endif /* PDFGRID_H_ */
